﻿Namespace moteurTauxGaranti2

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ParamSimulInd

        Protected _Nom As String
        Protected _ChocMin As Double
        Protected _ChocMax As Double
        Protected _Pas As Double
        Protected _NbIterations As Integer

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New(ByVal nom As String)
            _Nom = nom
            _NbIterations = 1
        End Sub
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            _NbIterations = 1
        End Sub

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Property Nom() As String
            Get
                Return _Nom
            End Get
            Set(ByVal value As String)
                _Nom = value
            End Set
        End Property
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Property chocMin() As Double
            Get
                Return _ChocMin
            End Get
            Set(ByVal value As Double)
                If _ChocMin <> value Then
                    Dim e As New paramSimulIndInfoChocEventArgs(_ChocMin)
                    _ChocMin = value
                    RaiseEvent ChocMin_HasChanged(Me, e)
                    calculeNbIterations()
                End If
            End Set
        End Property
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Property chocMax() As Double
            Get
                Return _ChocMax
            End Get
            Set(ByVal value As Double)
                If _ChocMax <> value Then
                    Dim e As New paramSimulIndInfoChocEventArgs(_ChocMax)
                    _ChocMax = value
                    RaiseEvent ChocMax_HasChanged(Me, e)
                    calculeNbIterations()
                End If
            End Set
        End Property
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Property Pas() As Double
            Get
                Return _Pas
            End Get
            Set(ByVal value As Double)
                If _Pas <> value Then
                    Dim e As New paramSimulIndInfoChocEventArgs(_Pas)
                    _Pas = value
                    RaiseEvent Pas_HasChanged(Me, e)
                    calculeNbIterations()
                End If
            End Set
        End Property
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public ReadOnly Property NbIterations()
            Get
                Return _NbIterations
            End Get
        End Property
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Protected Sub calculeNbIterations()
            Dim newNbIterations As Double = 0
            If _Pas <> 0 Then
                newNbIterations = Int((_ChocMax - _ChocMin) / _Pas) + 1
            Else
                If _ChocMax <> _ChocMin Then
                    newNbIterations = 2
                Else
                    newNbIterations = 1
                End If
            End If
            If _NbIterations <> newNbIterations Then
                Dim e As New paramSimulIndNbIterationsEventArgs(_NbIterations)
                _NbIterations = newNbIterations
                RaiseEvent NbIterations_HasChanged(Me, e)
            End If
        End Sub

        Public Event NbIterations_HasChanged As paramSimulIndNbIterationsEventHandler
        Public Event Pas_HasChanged As ParamSimulIndInfoChocEventHandler
        Public Event ChocMin_HasChanged As ParamSimulIndInfoChocEventHandler
        Public Event ChocMax_HasChanged As ParamSimulIndInfoChocEventHandler
    End Class
End Namespace